package br.com.DAO;

import java.util.ArrayList;
import java.util.List;

import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;

import br.com.Bean.DisciplinaBean;
import br.com.Bean.ForumBean;
import br.com.Bean.MuralBean;
import br.com.Bean.UsuarioBean;

public class MuralDAO {
	
	public void salva(MuralBean muralBean, DisciplinaBean disciplinaBean, UsuarioBean usuarioBean){
		ParseObject mural = new ParseObject("Mural");
		mural.put("aviso", muralBean.getAviso());
		mural.put("data", muralBean.getData());
		mural.put("idUsuario", usuarioBean.getId());
		mural.put("idDisciplina", disciplinaBean.getId());
		mural.put("observacao", muralBean.getObservacao());
		mural.saveInBackground();
	}
	
	public void deleta(MuralBean muralBean){
		 List<ParseObject> todos = null;
		 List<DisciplinaBean> listaTodos = new ArrayList<>();
		
		ParseQuery query = new ParseQuery("Mural");
		query.whereEqualTo("objectId", muralBean.getId());
		 try {
				todos = query.find();
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 
		 if(todos != null){
			 for (ParseObject todo : todos) {
               MuralBean m = new MuralBean();
               	m.setId(todo.getObjectId());
               	todo.deleteInBackground();
               	System.out.println("DELETOU");
         //       listaTodos.add(d);
            }
		 }
	}
	
	public List<MuralBean> listaMural(DisciplinaBean disciplinaBean){
		 List<ParseObject> todos = null;
		 List<MuralBean> listaTodos = new ArrayList<>();
		 UsuarioDAO usuarioDAO = new UsuarioDAO();
		
		ParseQuery query = new ParseQuery("Mural");
		query.whereEqualTo("idDisciplina", disciplinaBean.getId());
		 try {
				todos = query.find();
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 
		 if(todos != null){
			 for (ParseObject todo : todos) {
				 MuralBean m = new MuralBean();
				 	m.setId(todo.getObjectId());
				 	m.setAviso(todo.getString("aviso"));
				 	m.setData(todo.getDate("data"));
				 	m.setUsuario(usuarioDAO.buscaPeloId(todo.getString("idUsuario")));
				 	m.setObservacao(todo.getString("observacao"));
					
				 listaTodos.add(m);
             }
		 }
		 
		return listaTodos;
	}
}
